<?php
#
# author: Cody Sorgenfrey
# (c)2012 South Hill Calvary Chapel
#

include_once("../mysql/database_info.php");
include_once("common.php");
include_once("../mysql/common.php");
include_once("libraryactions.php");

$title = "SHCC Office Library";
$meta_key='books, lend, borrow, christian bookstore';
$meta_desc="The vast collection of spiritual wisdom at the South Hill Calvary Chapel Office.";
$morehtml=NULL;
$morejava="
<script type='text/javascript'>
	function searchTable(input)
	{
	$(document).ready(function(){
		if (input.value == ''){
			$('.dotted_lines').css('display', 'table-row');
			$('.dotted_lines').children().css('opacity', '1');
			document.getElementById('count').innerHTML = $('.dotted_lines').length;
		} else {
			$('.dotted_lines').css('display', 'none');
			$('.dotted_lines').children().css('opacity', '.1');
			var tableRows = document.getElementsByTagName('TR');
			var count = 0;
			for (var x=2;x<tableRows.length;x++){
				var rowCells = tableRows[x].getElementsByTagName('TD');
				for (var y=0;y<rowCells.length;y++){
					var expr = new RegExp(input.value, 'i');
					rowCells[y].style.opacity = '.1';
					try {	
						if (rowCells[y].childNodes.length > 1){
							var offSet = rowCells[y].childNodes[0].innerHTML.search(expr);
						} else {
							var offSet = rowCells[y].innerHTML.search(expr);	
						}
						if (offSet != -1){
							rowCells[y].parentNode.style.display = 'table-row';
							rowCells[y].style.opacity = '1';
							count++;
						}
					} catch(err){
						console.log('cell '+y+' skipped due to error');
					}
				}
			}
		document.getElementById('count').innerHTML = count;
		}
	});
	}
	function searchTableFor(str)
	{
		document.getElementById('searchBar').value = str;
		searchTable(document.getElementById('searchBar'));
		$(document).ready(function(){
		$('.dotted_lines').children().css('opacity', '1');
		});
	}
</script>";
startPageNoPageContent($title, $meta_key, $meta_desc, $morehtml, $morejava);
connect_select_test("SHCCLibrary");
printLoginAndOutStuff();
if ($_REQUEST['librarian_cookie'] == 1) printLibrarianPanel(); 
printf("<div class='pageContent'>\n");
if ($_REQUEST['librarian_cookie'] != 1 && $_GET['login'] != 1){	
		printf("<p>Welcome to the office library catalog! At the church office we have a few book shelves of books available for anyone in the church to borrow for a month or more to read. To check out a book see Whitney or one of the office staff and we will get you on your way!</p>");
}
printBookTable();
printf("</div>\n");
mysql_close();

endPage();
?>